<?php
// +-------------------------------------------------------------------------------
// | DingZone [ A Rapid Development Framework For Dingtalk ]
// +-------------------------------------------------------------------------------
// | 站点管理员后台首页相关Controller v1.0
// |
// | Copyright (c) 2014-2018 http://www.heimalanshi.com All rights reserved.
// | Author : Jie
// | Date : 2018-08-09
// +-------------------------------------------------------------------------------

namespace app\core\controller\site;

class IndexController extends SiteBaseController {
    /**
     * 后台首页
     */
    public function index() {
        $this->assign("indexUrl", "/core/site/");
        $this->assign("logoutUrl", "/core/site/logout");
        $this->assign("userAvatar", $this->siteAdmin['avatar']);
        $this->assign("userName", $this->siteAdmin['username']);
        $this->assign("menus", $this->_getMenus());
        $this->assign("userMenus", $this->_getUserMenus());
        return view();
    }

    private function _getUserMenus() {
        $userMenus = [];
        array_push($userMenus, [
            'title' => '账号编辑',
            'link' => '/core/site.user/profile'
        ]);

        array_push($userMenus, [
            'title' => '清理缓存',
            'link' => '/core/site.cache/clear'
        ]);

        return $userMenus;
    }

    /**
     * 获取菜单
     *
     * @return array
     */
    private function _getMenus() {
        $menus = [];
        array_push($menus, [
            "title" => "企业管理",
            "link" => "/core/site.enterprise/all",
        ]);
        array_push($menus, [
            "title" => "模块管理",
            "left" => [
                [
                    "title" => "已启用",
                    "link" => "/core/site.module/all/active"
                ],
                [
                    "title" => "已停用",
                    "link" => "/core/site.module/all/inactive"
                ],
                [
                    "title" => "未安装",
                    "link" => "/core/site.module/all/undownload,uninstall"
                ]
            ]
        ]);
        array_push($menus, [
            "title" => "站点管理",
            "left" => [
                [
                    "title" => "站点设置",
                    "link" => "/core/site.config/index",
                ],
                [
                    "title" => "定时任务管理",
                    "link" => "/core/site.cron/all"
                ],
                [
                    "title" => "备份管理",
                    "link" => "/core/site.backup/all"
                ],
                [
                    "title" => "数据库管理",
                    "link" => "/core/site.sys/db"
                ],
                [
                    "title" => "系统情况",
                    "link" => "/core/site.sys/index"
                ]
            ]
        ]);

        return $menus;
    }
}
